#include <REGX52.H>
#include "Timer0.h"
#include "LCD1602.H"
unsigned long Steps=0;
unsigned char code Control_Code[]={0x08,0x0c,0x04,0x06,0x02,0x03,0x01,0x09};
unsigned int T0Count;
void Step_Motor_Init()
{
	Timer0Init();
}

/* 步进电机启动函数，angle-需转过的角度 */
void Step_Motor_Run(unsigned long angle)
{
	//在计算前关闭中断，完成后再打开，以避免中断打断计算过程而造成错误
	//EA = 0;
	Steps = (angle * 4076)/ 360 ; //实测为 4076 拍转动一圈
	//EA = 1;
}

void Timer0_Routine() interrupt 1
{
	
	//unsigned char Temp;
	TL0 = 0x66;		//设置定时初始值
	TH0 = 0xFC;		//设置定时初始值
	if(Steps>0)
	{		
		Steps--;
		T0Count++;
		T0Count%=8;
//		Temp=P1&0xF0;//低四位清零
//		P1=Temp|Control_Code[T0Count];//给低四位 赋值	
		P1=Control_Code[T0Count];		
		LCD_ShowNum(1,1,T0Count,2);  
		LCD_ShowNum(2,1,Steps,5);  
	}
	else
		P1=P1&0xF0;
	
}
